﻿using Newbie.RabbitMQ;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Newbie.RabbitMQ
{
    [Serializable]
    public class EventMessage<T> : IEventMessage<T>
    {
        /// <summary>
        /// 消息交换模式，1、短暂，2、持久
        /// </summary>
        public byte deliveryMode{ get; set;}
        /// <summary>
        /// 消息Body
        /// </summary>
        public T MessageEntity { get; set; }
        /// <summary>
        /// 是否操作成功
        /// </summary>
        public bool IsOperationOk { get; set; }
        /// <summary>
        /// 由二进制数据流转换成对应的消息实体
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        public IEventMessage<T> BuildEventMessageResult(byte[] body)
        {
            return MessageSerializerFactory.CreateMessageSerializerInstance().BytesDeseriallizer<IEventMessage<T>>(body);
        }
    }
}
